<!DOCTYPE html>
<%@include file="../include/init.jsp"%>
<ef:priv priv="Platform.Role"/>
<html xmlns="http://www.w3.org/1999/xhtml" scroll="no">
<%@ taglib prefix="ef" uri="control"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${Title}</title>
<link rel="shortcut icon" href="${res}favicon.ico" type="image/x-icon" />
 <!--Basic Styles-->
<link href="../framework/css/font.css" rel="stylesheet" />
<link href="../framework/miniui/themes/material/miniui.css" rel="stylesheet" />
<link href="../framework/css/app.min.1.css" rel="stylesheet" type="text/css" />
<link href="../framework/css/app.min.2.css" rel="stylesheet" type="text/css" />
<script src="../framework/main.js" type="text/javascript"></script>
<style type="text/css">
    html, body{
        margin:0;padding:0;border:0;width:100%;height:100%;overflow:hidden;
    }    
    </style>
</head>
<ef:init method="Role.init">
<body class="body-detail">
<script>
function addUserToRole(){
	if(!$V('RoleCode')||$V('RoleCode')=="null"){
		top.mini.alert("@{Common.PleaseSelectRowFirst}!");
		return;
	}
	mini.open({
		width : 680,
		height : 390,
		title : "@{Role.UserList}",
		url : "${ctx}platform/roleUserListDialog.jhtml?RoleCode="+$V('#RoleCode'),
		onOk : addUserToRoleSave
	});
	
}

function addUserToRoleSave(){
	var arr = $DW.mini.get('dg1').getSelectedValue();
	if(!arr||arr.length==0){
		top.mini.alert("@{Common.PleaseSelectRowFirst}!");
		return;
	}
	var dc = {RoleCode:$V('RoleCode'),UserNames:arr.join()};
	Server.sendRequest("Role.addUserToRole",dc,function(response){
		if(response.Status == 1) {
			toastr.success(response.Message);
			$D.close();
			mini.get('dg1').reload();
		} else {
			top.mini.alert(response.Message,null,response.Status);
		}
	});
}

function delUserFromRole(){
	var arr = mini.get('dg1').getSelectedValue();
	if(!arr||arr.length==0){
		top.mini.alert("@{Common.PleaseSelectRowFirst}!");
		return;
	}
	top.mini.confirm("@{Common.ConfirmDelete}？",function(action){
		var dc = {RoleCode:$('#RoleCode').val(),UserNames:arr.join()};
		if(action == "ok"){
			Server.sendRequest("Role.delUserFromRole",dc,function(response){
				if(response.Status == 1) {
					toastr.success(response.Message);
					mini.get('dg1').clearSelect();
					mini.get('dg1').reload();
				} else {
					mini.get(response.Message,null,response.Status);
				}
			});	
		}
	});
}
Page.onLoad(function(){
	if(!$V("RoleCode")){
		mini.get('dg1').disable();
		mini.get('addBtn').disable();
		mini.get('removeBtn').disable();
	} else {
		mini.get('dg1').load({ID:'${RoleCode}'});	
	}
});
</script>

<div class="mini-toolbar" style="margin:2px 10px;" id="toolbar1" plain="true">
     <a priv="Platform.Role.AddUser" id="addBtn" class="mini-button" iconCls="icon-active-user" onClick="addUserToBranch()" plain="true"><ef:lang id="Role.AddUser">添加用户到角色</ef:lang></a>
     <a priv="Platform.Role.RemoveUser" id="removeBtn" class="mini-button" iconCls="icon-remove" onClick="delUserFromRole()" plain="true"><ef:lang id="Role.RemoveUser">从角色中删除用户</ef:lang></a>
</div>
<div class="mini-fit" style="padding:0 10px 10px 10px;">
	<div id="dg1" class="mini-datagrid z-depth-1" style="width:100%;height:100%;" method="Role.bindGrid"  idField="UserName" multiSelect="true">
	    <div property="columns">
	       	<div type="indexcolumn"></div>
	        <div type="checkcolumn" ></div>        
            <div field="UserName" width="13%"><ef:lang id="Common.UserName">用户名</ef:lang></div>
            <div field="RealName" width="12%"><ef:lang id="User.RealName">真实姓名</ef:lang></div>
            <div field="RoleNames" width="40%"><ef:lang id="User.Roles">所属角色</ef:lang></div>
	    </div>
	</div>
</div>
</body>
</ef:init>
</html>